home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
0132.ZIP
/
MODEM07.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-11-02
|
5KB
|
156 lines
{.PL72}
PROGRAM MODEM07;
CONST
fnlen = 12; (* filename length *)
dots = 50; (* sector counting dots per line *)
secsiz = $80;
datamask = $7F;
bufsecs = 128; (* number of file sectors to buffer *)
bufsiz = $3FFF; (* text and file buffer size 16k *)
errormax = 10; (* maximum errors before abort *)
retrymax = 5; (* maximum retryes before abort *)
soh = 1; (* start of sector character *)
eot = 4; (* end of transmission character *)
ack = 6; (* acknowledge sector transmission *)
nak = 21; (* error in transmission detected *)
can = 24; (* cancel transmission *)
bell = #7;
tab = #9;
lf = #10;
cr = #13;
ctrlz = #26; (* end of text file character *)
ctrlc = #3;
ctrlk = #11;
ctrll = #12;
ctrlq = #17;
ctrlr = #18;
ctrls = #19;
ctrlv = #22;
capture = ctrlc; (* toggle text capture *)
keep = ctrlk; (* keep text buffer *)
literal = ctrll; (* send literal character *)
quit = ctrlq; (* quit *)
receive = ctrlr; (* receive file by sectors *)
send = ctrls; (* send file by sectors *)
view = ctrlv; (* view data transferred *)
TYPE
fntype = string[fnlen];
VAR
timeout, asciiflag, showrecv, showtrans, bflag, viewflag : boolean;
kbdata, moddata, viewmode : char;
txtptr, n : integer;
txbuff : array [0..bufsiz] of char;
xmbuff : array [0..bufsiz] of byte;
capturefile : file; (* file of char *)
xmodemfile : file; (* file of byte *)
cfilename, xfilename : fntype;
procedure hexwrite (cc : byte);
var
hch, hcl : integer;
begin
hch := $30 + ((cc and $F0) div 16);
if hch > $39 then hch := hch + 7;
hcl := $30 + (cc and $F);
if hcl > $39 then hcl := hcl + 7;
write (#$1B,'l',chr(hch),chr(hcl),#$1B,'m');
end;
{$I INNOCIO.PAS}
{$I SENDCHAR.PAS}
{$I READCHAR.PAS}
{$I SENDFILE.PAS}
{$I READFILE.PAS}
{$I INSTRUCT.PAS }
begin
asciiflag := false;
showrecv := false;
showtrans := false;
bflag := false;
viewflag := false;
timeout := false;
txtptr := 0;
instruct;
init_modem;
(* the main loop *)
repeat
kbdata :=getkbdata;
case kbdata of
capture : begin
bflag := not bflag;
write ('Capture ');
if bflag then write ('initiated') else write ('terminated');
writeln (', ',bufsiz-txtptr,' bytes free.');
end;
keep : begin
if txtptr = 0 then writeln ('Nothing to save.')
else
begin
write ('Save as what file : ');
readln (cfilename);
assign (capturefile,cfilename);
rewrite (capturefile);
txbuff[txtptr] := ctrlz;
blockwrite(capturefile,txbuff[0],(txtptr div secsiz) + 1);
close (capturefile);
txtptr := 0;
end
end;
receive : begin
write ('Receive what file : ');
readln (xfilename);
readfile (xfilename);
end;
send : begin
write ('Send what file : ');
readln (xfilename);
sendfile (xfilename);
end;
view : begin
viewflag := not viewflag;
if viewflag then
begin
write ('View as ascii or hex : ');
readln (viewmode);
write ('Display will be in ');
if viewmode in ['a','A'] then writeln ('ascii.') else
writeln ('hex.');
end;
end;
literal : begin
repeat
kbdata := getkbdata;
until kbdata > #0;
modem_output(ord(kbdata));
end;
else
if kbdata > #0 then modem_output(ord(kbdata));
if modem_input_ready then
begin
moddata := chr(modem_input);
if (bflag and (txtptr < bufsiz)) then
begin
txbuff[txtptr] := moddata;
txtptr := txtptr + 1;
end else if bflag then writeln (cr,lf,bell,'Capture buffer overflow');
write (moddata);
end;
end;
until kbdata = quit;
hang_up;
end.
uffer overflow');
write (moddata);
end;
end;